<?php
if (!defined('APPPATH')) exit('No direct script access allowed');

include_once(APPPATH.'libraries/api/core/MySQL.php');
include_once(APPPATH.'libraries/api/core/Services.php');

class Panel extends Services {
    
	public static function panelSetupGet() {
        $query = "SELECT * FROM `admin_panel` WHERE `option` != 0; ";
        $result = MySQL::selectGetRow($query);
        if(parent::check($result)) {
            return $result;
        } else {
            return array();
        }
	}
    
	public static function adminOptionDisable($admin_panel_id) {
		if(parent::checkArguments($admin_panel_id)) {
			$query = "UPDATE `admin_panel` SET `option` = 0 WHERE `admin_panel_id` = $admin_panel_id; ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
    
	public static function adminOptionEnable($admin_panel_id) {
		if(parent::checkArguments($admin_panel_id)) {
			$query = "UPDATE `admin_panel` SET `option` = 1 WHERE `admin_panel_id` = $admin_panel_id; ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	
	public static function adminOptionName($admin_panel_id, $title) {
		if(parent::checkArguments(array($admin_panel_id, $title))) {
			$query = "UPDATE `admin_panel` SET `title` = '$title' WHERE `admin_panel_id` = $admin_panel_id; ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
    
	public static function adminMenusList() {
        $query = "SELECT * FROM `admin_panel` WHERE `object_id` IS NULL; ";
        $result = MySQL::selectGetArray($query);
        if(parent::check($result)) {
            return $result;
        } else {
            return array();
        }
	}
    
	public static function adminMenuGet($admin_panel_id) {
		if(parent::checkArguments($admin_panel_id)) {
			$query = "SELECT * FROM `admin_panel` WHERE `admin_panel_id` = $admin_panel_id; ";
			$result = MySQL::selectGetRow($query);
			if(parent::check($result)) {
				return $result;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}    
    
	public static function adminOptionsList($object_id) {
		if(parent::checkArguments($object_id)) {
			$query = "SELECT * FROM `admin_panel` WHERE `object_id` = $object_id; ";
			$result = MySQL::selectGetArray($query);
			if(parent::check($result)) {
				return $result;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
    
	public static function adminOptionsDisabling() {
		$query = "UPDATE `admin_panel` SET `option` = 0 WHERE `object_id` IS NOT NULL; ";
		$result = MySQL::update($query);
		if(parent::check($result)) {
			return true;
		} else {
			return false;
		}
	}    
    
}

?>
